//
//  WH_ShareOrderController.m
//  App_6.23
//
//  Created by wanghao on 16/6/27.
//  Copyright © 2016年 wanghao. All rights reserved.
//

#import "WH_ShareOrderController.h"
#import "WH_ShareOrderCell.h"
#import "WH_Home.h"
#import "WH_ShareDetailVC.h"

@interface WH_ShareOrderController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) NSMutableArray *dataArr;
@property (nonatomic, copy) NSString *body;

@end

@implementation WH_ShareOrderController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"晒单分享";
    
    self.dataArr = [NSMutableArray array];
    [self createEmptylist];
    [self createTab];
    [self postData];
    [self createHub];
    [self hubShow];
}
-(void)createTab{
    
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-44) style:UITableViewStylePlain];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.rowHeight = 250;
    self.myTableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_myTableView];
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    //自定义cell Xib注册
    [self.myTableView registerNib:[UINib nibWithNibName:@"WH_ShareOrderCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"WH_ShareOrderCell"];
}


-(void)postData{
    
    
    if (_indexShare == 101) {
        
        _body = [NSString stringWithFormat:@"action=order_show_all"];
        
    }else{

        _body = [NSString stringWithFormat:@"action=order_show&product_id=%@",self.showID];
    }
    [WH_AppTools postUrl:URLstr body:_body result:HXJSON requestStyle:HXRequestString headerFile:nil success:^(id result) {
        
        
        NSDictionary *dic = result;
        NSArray *order_show_array = [dic objectForKey:@"order_show_array"];
        for (NSDictionary *dic in order_show_array) {
            
            WH_Home *show = [WH_Home modelWithDictionary:dic];
            [self.dataArr addObject:show];
        }
        if (_dataArr.count == 0) {
            
            [self bringSubView];
        }
        [self hubDismiss];
        [self.myTableView reloadData];
    } failure:^(NSError *error) {
        
        
    }];
    
}

#pragma mark - tableView&&delegate&datasoure

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return self.dataArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *shareCell = @"WH_ShareOrderCell";
    WH_ShareOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:shareCell];
    cell.showOrder = self.dataArr[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    WH_ShareDetailVC *detaVC = [[WH_ShareDetailVC alloc] init];
    detaVC.detailModel = self.dataArr[indexPath.row];
    [self.navigationController pushViewController:detaVC animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)viewWillAppear:(BOOL)animated{
    
    
    [self.tabBarController.tabBar setHidden:YES];
}
-(void)viewWillDisappear:(BOOL)animated{
    
    
    [self.tabBarController.tabBar setHidden:NO];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
